package com.erp.programmer.controller;


import com.erp.programmer.bean.CodeMsg;
import com.erp.programmer.dto.OutWarehouseOrderDto;
import com.erp.programmer.dto.PageDto;
import com.erp.programmer.dto.ResponseDto;
import com.erp.programmer.dto.SaleOrderDto;
import com.erp.programmer.service.IOutWarehouseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Takagi3
 * @since 2021-05-26
 */

@CrossOrigin
@RestController
@RequestMapping("/out_warehouse_order")
public class OutWarehouseOrderController {

    @Autowired
    private IOutWarehouseOrderService iOutWarehouseOrderService;

    /**
     * 分页
     *新增销售订单信息
     */
    @PostMapping("/save")
    public ResponseDto<PageDto<OutWarehouseOrderDto>> saveOutWarehouseOrder(@RequestBody SaleOrderDto saleOrderDto) {
        //非空判断
        if (saleOrderDto == null) {
            return ResponseDto.errorByMsg(CodeMsg.DATA_ERROR);
        }
/*        //销售订单进行统一表单验证
        CodeMsg validate = ValidateEntityUtil.validate(saleOrderDto);
        if (!validate.getCode().equals(CodeMsg.SUCCESS.getCode())) {
            return ResponseDto.errorByMsg(validate);
        }*/

        return iOutWarehouseOrderService.saveOutWarehouseOrder(saleOrderDto);
    }

    /**
     * 分页
     * 搜索获取全部销售信息
     */
    @PostMapping("/get_data")
    public ResponseDto<PageDto<OutWarehouseOrderDto>> getOutWarehouseOrder(@RequestBody PageDto<OutWarehouseOrderDto> pageDto) {
        if (pageDto==null) {
            ResponseDto.errorByMsg(CodeMsg.DATA_ERROR);
        }
        return iOutWarehouseOrderService.getOutWarehouseOrders(pageDto);
    }

}

